from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session

from core.dao.cms_car_dao import CmsCarDao
from core.entity.vo.view_models import CarModelForPage, CarModelForAll, CarModelForAllTrack, CarMinitorObjectForQuery


class CmsCarService:
    """
    高德终端service
    """

    @classmethod
    def get_cms_car_like_name(cls, result_db: Session, car_number: str):
        """
        获取参数配置列表信息service
        :param result_db: orm对象
        :param query_object: 查询参数对象
        :return: 参数配置列表信息对象
        """
        cms_car_list = CmsCarDao.get_cms_car_like_car_number(result_db, car_number)

        return cms_car_list

    @classmethod
    def get_cms_car_list(cls, result_db: Session, car: CarMinitorObjectForQuery):
        """
        获取参数配置列表信息service
        :param result_db: orm对象
        :param offset: 分页偏移量
        :param limit: 每页数据量
        :return: 参数配置列表信息对象
        """
        cms_car_list = CmsCarDao.get_cms_car_list(result_db,car)

        return cms_car_list

    @classmethod
    def get_cms_car_list_all(cls, result_db: Session):

        cms_car_list = CmsCarDao.get_cms_car_list_all(result_db)

        cms_car_list_models = [CarModelForAll(**dict(zip(CarModelForAll.__fields__.keys(), car))) for car in
                               cms_car_list]

        return cms_car_list_models

    @classmethod
    def get_cms_car_list_all_track(cls, result_db: Session):

        cms_car_list = CmsCarDao.get_cms_car_list_all_track(result_db)

        cms_car_list_models = [CarModelForAllTrack(**dict(zip(CarModelForAllTrack.__fields__.keys(), car))) for car in
                               cms_car_list]

        return cms_car_list_models